// utils/storage.js
const getMidnightTimestamp = () => {
  const now = new Date();
  // 设置为第二天的0点（即当天晚上12点）
  const midnight = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1, 0, 0, 0, 0);
  console.log("设定的时间",midnight)
  return midnight.getTime();
};

const setDataWithExpiration = (key, value) => {
  const expiration = getMidnightTimestamp();
  wx.setStorageSync(key, { value, expiration });
};

const getDataWithExpiration = (key) => {
  const data = wx.getStorageSync(key) || {};
  console.log(data,123,key)
  let aa = new Date();
  console.log("对比的时间",aa)
  let asdf = aa.getTime();
  // console.log(asdf)
  if (data.expiration && data.expiration > asdf) {
    return data.value;
  }
  return null;
};

export { setDataWithExpiration, getDataWithExpiration };